package tech.yunqian.slim.project.controller;

import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import tech.yunqian.slim.framework.aspectj.annotation.ValidateRequest;
import tech.yunqian.slim.framework.web.AjaxResult;
import tech.yunqian.slim.framework.web.Response;
import tech.yunqian.slim.project.domain.Nop;
import tech.yunqian.slim.project.service.NopService;

@RestController
@RequestMapping("/api/nop")
public class NopController {
    @Autowired
    private NopService nopService;

    @ValidateRequest
//    @ValidatePermission(roles = {"admin"})
    @PostMapping(value = "/gotcha", produces = "application/json;charset=UTF-8")
    public AjaxResult Gotcha(@RequestBody JSONObject request) {
        int id = request.getIntValue("id");
        Nop nop = nopService.Gotcha(id);
        if (nop == null) {
            return AjaxResult.error(Response.NOT_FOUND.getMessage());
        }
        return AjaxResult.success(Response.OK.getMessage(), nop);
    }
}
